package bairui.international.console.web.controller.advance.category.product;

/**
 *
 * ExcelOutput_ExcelExport_Output_Admin_Detail
 * excel输出
 */
class ExcelOutput_ExcelExport_Output_Admin_Detail

{

	/**
	 * 创建sheet
	 */
	public static com.sh_lianjing.file.excel.write.ExcelWriter createSheet(
		String sheetName,
		java.util.List<Model> list
	) throws Exception{
		return createSheet(sheetName, com.sh_lianjing.file.excel.write.ExcelWriter.newInstanceExcel2007BigData(), list);
	}
	
	public static com.sh_lianjing.file.excel.write.ExcelWriter createSheet(
		String sheetName,
		com.sh_lianjing.file.excel.write.ExcelWriter writer,
		java.util.List<Model> list
	) throws Exception{
		return createSheet(sheetName, writer, Model.class, list, null);
	}

	public static <E extends Model, D> com.sh_lianjing.file.excel.write.ExcelWriter createSheet(
		String sheetName,
		com.sh_lianjing.file.excel.write.ExcelWriter writer,
		Class<E> type,
		java.util.List<E> list,
		D headCommentsData
	) throws Exception{
		return writer
				.createSheet(
					sheetName, 
					type,
					list,
					headCommentsData
				);
	}

	/**
	 * 输出文件
	 */
	public static void output(
		java.util.List<bairui.international.model.domain.jpa.TB_Product> list,
		javax.servlet.http.HttpServletRequest request,
		javax.servlet.http.HttpServletResponse response
	) throws Exception{
		java.util.List<Model> newContent = new java.util.ArrayList<>();
		for(bairui.international.model.domain.jpa.TB_Product bean : list){
			newContent.add(new Model(bean));
		}
		output(
			"产品", 
			createSheet("产品", newContent), 
			request, 
			response
		);
	}

	public static void output(
		String fileName,
		com.sh_lianjing.file.excel.write.ExcelWriter writer,
		javax.servlet.http.HttpServletRequest request,
		javax.servlet.http.HttpServletResponse response
	) throws Exception{
		// 设置格式
		com.lianjing.sh.web.common.util.Util_Web.setDownloadFileName(request, response, fileName+".xlsx");
		response.setContentType(org.springframework.http.MediaType.APPLICATION_XML_VALUE);
		// 生成excel并输出
		try{
			writer.writeTo(response.getOutputStream());
		} finally {
			writer.close();
		};
	}

	
	/**
	 * 排序扩展接口
	 */
	static interface OrderExtends {
		org.springframework.data.domain.Sort gainProductCategory(
			org.springframework.data.domain.Sort.Direction direction
		);
		
	
		default org.springframework.data.domain.Sort sort(
			org.springframework.data.domain.Sort.Direction direction,
			com.querydsl.core.types.dsl.ComparableExpressionBase<?> ... sortBase
		){
			return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, sortBase);
		}
	
		default com.querydsl.core.types.OrderSpecifier<?> order(
			org.springframework.data.domain.Sort.Direction direction,
			com.querydsl.core.types.dsl.ComparableExpressionBase<?> orderBase
		){
			return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.orderTrans(direction, orderBase);
		}
	}
	
	/**
	 * 排序
	 */
	final static org.springframework.data.domain.Sort sort(
		bairui.international.model.domain.jpa.QTB_Product QRoot,
		javax.servlet.http.HttpServletRequest request
		,OrderExtends orderExtends
	){
		/*
		 * 排序属性
		 */
		// orderBy @RequestParam(name="orderBy", required=false, defaultValue="orderValue") String orderBy
		String orderByPara = request.getParameter(com.lianjing.sh.web.separatepage.OrderInfo.OrderBy);
		if(null == orderByPara){
			orderByPara = "id";
		}
		// orderWay @RequestParam(name="orderWay", required=false, defaultValue="DESC") OrderWay orderWay
		String orderWayPara = request.getParameter(com.lianjing.sh.web.separatepage.OrderInfo.OrderWay);
		if(null == orderWayPara){
			orderWayPara = "DESC";
		}
		org.springframework.data.domain.Sort.Direction direction = org.springframework.data.domain.Sort.Direction.valueOf(orderWayPara);
	
		//
		switch(orderByPara){
			case "number":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.number);
			case "name":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.name);
			case "productCategoryToString":		return orderExtends.gainProductCategory(direction);
			case "state":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.state);
			case "exchange":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.exchange);
			case "divideRate":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.divideRate);
			case "createTime":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.createTime);
			case "modifyTime":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.modifyTime);
			case "id":	return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.id);
			default:
				throw new RuntimeException();
		}
	}
	

	@com.sh_lianjing.file.excel.write.annotation.WriteExcel
	@SuppressWarnings(value="serial")
	
	public static class Model extends bairui.international.model.domain.jpa.TB_Product{
	
		/**
		 * 构造函数
		 */
		@lombok.Getter @com.fasterxml.jackson.annotation.JsonIgnore
		private bairui.international.model.domain.jpa.TB_Product _origin;
	
		public Model(
			bairui.international.model.domain.jpa.TB_Product bean
		) {
			this._origin = bean;
			if(null != bean){
				this.setNumber(bean.getNumber());
				this.setName(bean.getName());
				this.setProductCategory(bean.getProductCategory());
				this.setState(bean.getState());
				this.setExchange(bean.getExchange());
				this.setDivideRate(bean.getDivideRate());
				this.setCreateTime(bean.getCreateTime());
				this.setModifyTime(bean.getModifyTime());
			}
		}
		
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(1)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "代码")
		
		@Override
		public String getNumber() {
			return (String)super.getNumber();
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(2)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "名称")
		
		@Override
		public String getName() {
			return (String)super.getName();
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(3)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "分类")
		public String getProductCategoryToString() {
			bairui.international.model.domain.jpa.TB_ProductCategory it = this.getProductCategory();
			if(null != it){
				return it.toString();
			}
			return null;
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(4)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "状态")
		
		@Override
		public bairui.international.model.status.State_Product getState() {
			return (bairui.international.model.status.State_Product)super.getState();
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(5)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "兑换积分值")
		
		@Override
		public Double getExchange() {
			return (Double)super.getExchange();
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(6)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "分成比率[%]")
		
		@Override
		public Double getDivideRate() {
			return (Double)super.getDivideRate();
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(7)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelDateFormat(pattern = "yyyy-MM-dd")
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "创建时间")
		
		@Override
		public java.util.Date getCreateTime() {
			return (java.util.Date)super.getCreateTime();
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(8)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelDateFormat(pattern = "yyyy-MM-dd")
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "最后修改时间")
		
		@Override
		public java.util.Date getModifyTime() {
			return (java.util.Date)super.getModifyTime();
		}
		
		
		/**
		 * 非继承属性
		 */
		
	
		/**
		 * 相关类
		 */
	}
	

}

